package com.yzg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzg.pojo.Brand;
import com.yzg.mapper.BrandMapper;
import com.yzg.service.BrandService;
import org.springframework.util.StringUtils;

/**
* @Author: decade
* @Description: ${description}
* @Date: 2021/1/13 18:26
**/
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService{
    @Autowired
    private BrandMapper brandMapper;

    // 获取品牌列表
    @Override
    public Map<String, Object> getBrandList(Integer page, Integer pageSize,String keyword) {
        IPage<Brand> pageParam = new Page<>(page,pageSize);
        QueryWrapper<Brand> wrapper = new QueryWrapper<>();
        if(keyword!="null"){
            if(keyword.trim()!=null&&!"".equals(keyword)){
                //条件查询
                wrapper.like("name", keyword);
            }
        }

        brandMapper.selectPage(pageParam, wrapper);
        Map<String,Object> map = new HashMap<>();
        map.put("list", pageParam.getRecords());
        map.put("total", pageParam.getTotal());
        return map;
    }

    //是否为品牌制造商
    @Override
    public int updateFactoryStatus(Long id, Integer factoryStatus) {
        Brand brand = new Brand();
        brand.setId(id);
        brand.setFactoryStatus(factoryStatus);
        return brandMapper.updateById(brand);
    }

    //是否显示
    @Override
    public int updateShowStatus(Long id, Integer showStatus) {
        Brand brand = new Brand();
        brand.setId(id);
        brand.setShowStatus(showStatus);
        return brandMapper.updateById(brand);
    }

    //品牌编辑
    @Override
    public int updateBrand(Brand brand) {
        return brandMapper.updateById(brand);
    }


}
